<?php
require 'header.php';
require 'includes/db.php';
$tableName = 'our_team';

$where = '';
$id = isset($_GET['id']) ? $_GET['id'] : 0;
$total_users = CountAll('our_team');

########### Count total records in users table ##############

########### PAGING START ###########################

$rpp = 2;
// Record Per Page (offset)
$total_pages = ceil($total_users / $rpp);
$currentPage = isset($_GET['page']) ? $_GET['page'] : 1;
$index = $rpp * ($currentPage - 1);
// limit or from where we have to start fetching
?>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
     <?php
	if (isset($_GET['mode'])) {
		$query = mysql_query("select image from our_team where id='$id'");
		$image_name = mysql_fetch_array($query);
		$deleteFile = $image_name['image'];
		@unlink('images/upload/' . $deleteFile);
		$numRows = deleteby($tableName, $id);
		if ($numRows == 1) {
			echo success("Succefully Deleted");
		}
	}
	if (isset($_GET['status'])) {
		$newStatus = $_GET['status'] == 0 ? 1 : 0;
		$data = array('status' => $newStatus);
		$flag = updateById($tableName, $data, $id);
		echo success("Successfully Upadated #id $id");
	}
    ?>
    <b>OUR TEAM MEMBERS</b><a href="addteammember.php" class="input_setting" style="border-radius: 10px;"><span class="glyphicon glyphicon-plus-sign"></span> Add New</a></br></br>
    <table class="table table-striped">
        <thead>
            <tr>
                <th width="2%" align="right">Id</th>
                <th width="10%" align="right">Name</th>
                <th width="10%" align="right">Image</th>
                <th width="15%" align="right">Designation</th>
                <th width="10%" align="right">Facebook Id</th>
                <th width="10%" align="right">Twitter Id</th>
                <th width="10%" align="right">linkedin Id</th>
                <th width="40%" align="right">Description</th>
                <th width="5%" align="right">Status</th>
                <th width="5%" align="right">Action</th>
  </tr>
        </thead>
      
 <?php
        $sql = fetchAll($tableName,'','id',$index,$rpp);
        while ($data = mysql_fetch_assoc($sql)) {
        	$id=$data['id'];
			$status = getStatus($data['status']);
			$status = "<a style=\"text-decoration:none\" href=\"?id=$id&status=$data[status]&page=$currentPage\">$status </a>";
            ?>				<tbody>
                <tr>
                    <td><?= $data['id'] ?></td>
                    <td><?= $data['name'] ?></td>
                    <td align="center"><img height="30" width="90" src="upload/<?=$data['image'] ?>"><br/>
    <a target="_blank" href="upload/<?=$data['image'] ?>" >View in Full Size</a>
    </td>
                    <td><?= $data['designation'] ?></td>
                    <td><a href="<?=$data['fb_id']?>"></a></td>
                    <td><a href="<?=$data['twitter_id']?>"></a></td>
                    <td><?=$data['ln_id'] ?></td>
                    <td><?=$data['description'] ?></td>
                    <td><?=$status?></td>
                    <td><div><a onClick="return confirm('Are you sure to delete?')" href="?mode=del&id=<?=$data['id'] ?>&page=<?=$currentPage ?>" class="delete"><span class="glyphicon glyphicon-trash" style="font-size:30px; color: red;"></span></a>&nbsp;&nbsp;&nbsp;</div>
                        <br>
                        <div><a href="editteam.php?id=<?=$data['id'] ?>" class="edit"><span class="glyphicon glyphicon-edit" style="font-size:30px"></span></a></div>
                    </td>


                <?php } ?>
    </table>
    <ul class="pagination pagination-lg">

  <li class="disabled"><a href="#">&laquo;</a></li>

<?php
  for ($i=1; $i <= $total_pages ; $i++) {
    if($i==$currentPage) {
?>
  <li class="active"><a href="#"><?=$i ?> <span class="sr-only">(current)</span></a></li>

<?php
} else { //end current page if()
?>
  <li><a href="?page=<?=$i ?>"><?=$i ?></a></li>
<?php
} // end else
}//end for() for paging
?>

  <li><a href="#">&raquo;</a></li>
</ul>
                </div>

